<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:a="http://richfaces.org/a4j"
                template="template.xhtml">

    <!-- content -->
    <ui:define name="content">
        <h:form>	
            <p>		
                <div id="simple_input" class="quickSearch">				
                    <input id="search1" type="text"
                           onkeypress="return searchOnEnter(event)" onfocus="value=''"
                           onblur="if (value=='') value='#{messages['search_quicksearch']}'"
                           value="#{messages['search_quicksearch']}" />									
                    <input id="seachgo" type="button" value="#{messages['search_go']}"
                           onclick="searchQuick(); return false" /><br />
                    <small>
                        <a href="/seam-booking/search_adv.html" 
                           target="ifrm" onclick="searchToggle()">#{messages['search_advanced']}
                        </a>
                    </small>
                </div>
            </p>
            <div class="section">
                <h2>#{messages['hotel_list_header']}</h2>
                <a:outputPanel ajaxRendered="true">
                    <div class="messages">
                        <h:messages id="messages" infoClass="successBox"
                                    warnClass="infoBox" errorClass="warningBox" fatalClass="errorBox"
                                    globalOnly="true" showDetail="false" showSummary="true" />
                    </div>
                </a:outputPanel>
                <p>
                    <h:outputText rendered="#{searchTerms ne null}"
                                  value="#{messages['search_result_label']} #{hotelQuery.searchTextView} (" /><a:commandLink
                                  rendered="#{searchTerms ne null}"
                                  value="#{messages['search_result_clear']}"
                                  action="/main.xhtml"
                                  reRender="hotels,hotel_list,bottom_bar" status="gstat">
                        <a:actionparam name="qry" assignTo="#{hotelQuery.searchTerms}" value="" />
                        <a:actionparam name="firstResult" assignTo="#{firstResult}" value="0" />
                    </a:commandLink>
                    <h:outputText rendered="#{searchTerms ne null}" value=")" />
                </p>
                <a:jsFunction name="doSearch"
                              action="/main.xhtml"
                              reRender="hotel_list,bottom_bar" status="gstat"
                              eventsQueue="search" ignoreDupResponses="true">
                    <a:actionparam name="qry" assignTo="#{hotelQuery.searchTerms}" />
                    <a:actionparam name="firstResult" assignTo="#{hotelQuery.firstResult}" value="0" />
                </a:jsFunction>
                <a:jsFunction name="doDelete"
                              action="#{hotelDeletePage.doDelete}"
                              status="gstat"
                              eventsQueue="delete" ignoreDupResponses="true">
                    <a:actionparam name="hotelId" assignTo="#{hotelDeletePage.hotelId}" />
                </a:jsFunction>
                <div id="advanced_input" style="display: none">
                    <div class="dialog_input_shade"></div>
                    <div class="dialog_input"><iframe id="ifrm" name="ifrm"
                                                      frameborder="0" style="width: 100%" /></div>
                </div>

                <script type="text/javascript">
                //<![CDATA[
                var advanced = false;
                function searchToggle() {
                        advanced=!advanced;
                        if (advanced) {
                                document.getElementById('advanced_input').style.display='';
                        } else {
                                document.getElementById('advanced_input').style.display='none';
                        }
                }
                
                function deleteHotel(hotelId,hotelName) {
                    if (confirm('delete '+hotelName+' ?')) { 
                        doDelete(hotelId);
                    } 
                }

                function setIframeHeight(iframeName) {
                        var ifrm = document.getElementById(iframeName);
                        var height = ifrm.contentWindow.document.body.scrollHeight;
                        if (height>100) {
                                ifrm.style.height = height + 60 + "px";
                        }
                }

                function searchQuick() {
                        if (document.getElementById('search1').value == "#{messages['search_quicksearch']}") return false; 
                        var qry = document.getElementById('search1').value;
                        doSearch(qry);
                        return false;
                }
                function searchOnEnter(evt) {
                        evt = (evt) ? evt : event;
                        var target = (evt.target) ? evt.target : evt.srcElement;
                        var form = target.form;
                        var charCode = (evt.charCode) ? evt.charCode :
                                ((evt.which) ? evt.which : evt.keyCode);
                        if (charCode == 13) {
                                searchQuick();
                                return false;
                        }
                        return true;
                }
                //]]>
                </script>

                <a:outputPanel id="hotel_list">
                    <a:outputPanel id="infoPanelHotelList"
                                   rendered="#{hotelQuery.resultCount==0}">
                        <p><h:outputText value="No Hotel" /></p>
                    </a:outputPanel>
                    <h:dataTable id="hotels" value="#{hotelQuery.resultList}" 
                                 styleClass="bodyTable"
                                 var="hotel" rendered="#{hotelQuery.resultCount>0}">
                        <h:column id="column1">
                            <f:facet id="name" name="header">name</f:facet>
                            <a:commandLink action="#{hotelViewPage.show(hotel.id)}" status="gstat"
                                           value="#{hotel.name}" >
                            </a:commandLink>
                        </h:column>
                        <h:column id="column2">
                            <f:facet id="address" name="header">address</f:facet>
                            #{hotel.address}
                        </h:column>
                        <h:column id="column3">
                            <f:facet id="country" name="header">country</f:facet>
                            #{hotel.country}
                        </h:column>
                        <h:column id="column4">
                            <f:facet id="price" name="header">price</f:facet>
                            #{hotel.price}
                        </h:column>
                        <h:column id="column5">
                            <f:facet id="action" name="header">Action</f:facet>
                            <a:commandLink action="#{hotelEditPage.show(hotel.id)}" status="gstat"
                                           value="#{messages['hotel_action_edit']}" >
                            </a:commandLink>
                            <br />
                            <a href="#" onclick="deleteHotel('#{hotel.id}','#{hotel.name}')">#{messages['hotel_action_delete']}
                            </a>
                        </h:column>
                    </h:dataTable>
                </a:outputPanel>
                <a:outputPanel id="bottom_bar">
                    <div class="pagingBar">
                        <h:outputFormat
                            value="#{messages['hotel_list_pager_label']}"
                            rendered="#{hotelQuery.resultCount>0}">
                            <f:param value="#{hotelQuery.firstResult + 1}" />
                            <f:param value="#{hotelQuery.firstResult + hotelQuery.resultList.size()}" />
                            <f:param value="#{hotelQuery.resultCount}" />
                        </h:outputFormat>
                        <h:outputText value=" " rendered="#{hotelQuery.resultCount>0}" />
                        <a:commandLink
                            action="#{hotelQuery.first}"
                            rendered="#{hotelQuery.resultCount>0}"
                            disabled="#{!hotelQuery.previousExists}"
                            reRender="hotel_list,bottom_bar" status="gstat"
                            eventsQueue="paging" ignoreDupResponses="true">#{messages['dataScroller_first_link']}</a:commandLink><h:outputText
                            value=" | " rendered="#{hotelQuery.resultCount>0}" />
                        <a:commandLink
                            action="#{hotelQuery.previous}"
                            rendered="#{hotelQuery.resultCount>0}"
                            disabled="#{!hotelQuery.previousExists}"
                            reRender="hotel_list,bottom_bar" status="gstat"
                            eventsQueue="paging" ignoreDupResponses="true">#{messages['dataScroller_previous_link']}</a:commandLink>
                        <h:outputText value=" | " rendered="#{hotelQuery.resultCount>0}" />
                        <a:commandLink
                            action="#{hotelQuery.next}"
                            rendered="#{hotelQuery.resultCount>0}"
                            disabled="#{!hotelQuery.nextExists}"
                            reRender="hotel_list,bottom_bar" status="gstat"
                            eventsQueue="paging" ignoreDupResponses="true">#{messages['dataScroller_next_link']}</a:commandLink>
                        <h:outputText value=" | " rendered="#{hotelQuery.resultCount>0}" />
                        <a:commandLink
                            action="#{hotelQuery.last}"
                            rendered="#{hotelQuery.resultCount>0}"
                            disabled="#{!hotelQuery.nextExists}"
                            reRender="hotel_list,bottom_bar" status="gstat"
                            eventsQueue="paging" ignoreDupResponses="true">#{messages['dataScroller_last_link']}</a:commandLink>
                    </div>
                </a:outputPanel>
            </div>
            <div class="section">
                <a:commandLink action="/todo.xhtml" status="gstat"
                               value="#{messages['goto_todo_list']}" >
                </a:commandLink>
            </div>
        </h:form>
    </ui:define>

    <!-- sidebar -->
    <ui:define name="sidebar">

    </ui:define>

</ui:composition>
